﻿using System.Threading.Tasks;
using Aquarinum.WebSocekt.Core.Dtos;
using Microsoft.AspNetCore.Http;

namespace Aquarinum.Base.Infrastructure.WebSocket.Interface
{
    public interface IWebSocketRequestTransfer
    {
        /// <summary>
        ///     接受消息
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="messageJson"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        Task ReceiveAsync(System.Net.WebSockets.WebSocket socket,
            string messageJson, HttpContext context);

        /// <summary>
        ///     当连接建立时
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="clientid"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        Task OnConnected(System.Net.WebSockets.WebSocket socket, HandShakeDto clientid, HttpContext context);

        /// <summary>
        ///     链接断开
        /// </summary>
        /// <param name="socket"></param>
        /// <returns></returns>
        Task OnDisconnected(System.Net.WebSockets.WebSocket socket);

        /// <summary>
        ///     发送消息
        /// </summary>
        /// <param name="socket">soket连接对象</param>
        /// <param name="socketMessage">消息</param>
        /// <param name="expireSecond">消息过期时间(单位秒)</param>
        /// <param name="needPersistence">是否需要持久化</param>
        /// <param name="needReceipt">首付需要回执</param>
        /// <returns></returns>
        Task SendMessageAsync(System.Net.WebSockets.WebSocket socket, WebsocketMessageDto socketMessage,
            long expireSecond = 0, bool needPersistence = false, bool needReceipt = false);

        /// <summary>
        ///     发送消息(从全局字典中通过ID 找到socket 对象)
        /// </summary>
        /// <param name="toClientId"></param>
        /// <param name="socketMessage"></param>
        /// <param name="needPersistence">是否需要持久化</param>
        /// <param name="needReceipt">首付需要回执</param>
        /// <param name="expireSecond">消息过期时间(单位秒)</param>
        /// <returns></returns>
        Task SendMessageAsync(string toClientId, WebsocketMessageDto socketMessage, long expireSecond = 0,
            bool needPersistence = false, bool needReceipt = false);

        /// <summary>
        ///     广播发送全部消息
        /// </summary>
        /// <param name="socketMessage"></param>
        /// <param name="needPersistence">是否需要持久化</param>
        /// <param name="needReceipt">首付需要回执</param>
        /// <param name="expire">消息过期时间</param>
        /// <returns></returns>
        Task PublishMessageToAllAsync(WebsocketMessageDto socketMessage, long expireSecond = 0,
            bool needPersistence = false,
            bool needReceipt = false);

        /// <summary>
        ///     按照分组来广播消息
        /// </summary>
        /// <param name="groupId"></param>
        /// <param name="socketMessage"></param>
        /// <param name="needPersistence">是否需要持久化</param>
        /// <param name="needReceipt">首付需要回执</param>
        /// <param name="expireSecond">消息过期时间(单位秒)</param>
        /// <returns></returns>
        Task PublishMessageToGroupAsync(string groupId, WebsocketMessageDto socketMessage, long expireSecond = 0,
            bool needPersistence = false, bool needReceipt = false);
    }
}